home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14437 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  58 lines

  1. Path: csugrad.cs.vt.edu!not-for-mail
  2. From: rsuri@csugrad.cs.vt.edu (Raj Suri)
  3. Newsgroups: comp.lang.c++
  4. Subject: Template constructor problem
  5. Date: 30 Mar 1996 13:11:27 -0500
  6. Organization: Virginia Tech Computer Science Dept, Blacksburg, VA
  7. Message-ID: <4jjtgf$ebo@csugrad.cs.vt.edu>
  8. NNTP-Posting-Host: csugrad.cs.vt.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Ok, take this code using g++ v2.7
  12.  
  13. queue.h:
  14.  
  15. template <class QueueItem> class Queue {
  16.  private:
  17.   QueueItem buffer[100];
  18.   int head, tail, count;
  19.  
  20.  public:
  21.   Queue();
  22.   void Insert (QueueItem item);
  23.   QueueItem Remove();
  24.   int Size();
  25.   ~Queue();
  26. };
  27.  
  28. template <class QueueItem>
  29. Queue<QueueItem>::Queue() : count(0), head(0), tail(0) {}
  30.  
  31. .....[the rest of the mothods]
  32.  
  33.  
  34. main.cc:
  35.  
  36. #include<stdio.h>
  37. #include "queue.h"
  38.  
  39. Queue<int> myqueue;
  40.  
  41. main () {
  42.  
  43. }
  44.  
  45.  
  46. Compiler error when linking:
  47. collect2: ld returned 1 exit status
  48. /usr/lib/cmplrs/cc/ld:
  49. Undefined:
  50. Queue<int>::Queue(void)
  51.  
  52.  
  53. If I don't declare a queue object, then I don't get the linker error.  
  54. Any suggestion??  Thanks in advance.
  55.  
  56. -Raj
  57.  
  58.